Skip to content

Make Importable as Library#14

Closed
j4n wants to merge 2 commits intomainfrom
j4n/make-importable
Closed

Make Importable as Library#14
j4n wants to merge 2 commits intomainfrom
j4n/make-importable

Conversation

@j4n
Copy link
Copy Markdown

@j4n j4n commented Mar 10, 2026

Two commits to make cmping importable as a library:

Error Handling & Isolation

  • Add CMPingError exception for non-fatal error reporting
  • Add set_cli_output() to let library callers suppress terminal output
  • Convert sys.exit(1) to raise CMPingError in setup_accounts, wait_profiles_online, and wait_profiles_online_multi
  • Add accounts_dir parameter to perform_ping() for concurrent probe isolation (each caller can use its own DB directory)
  • Wrap perform_ping() in main() with try/except CMPingError

Logging

  • Add logging module with log = getLogger("cmping")
  • Convert all print() calls to log.debug/info/warning/error
  • Add logging.basicConfig() in main() keyed to verbose level
  • Change print_progress() to write to stderr with _cli_output guard
  • Gate per-message RTT lines and statistics on _cli_output flag
  • Replace Unicode spinner chars with ASCII for portability

@j4n j4n requested a review from hpk42 March 10, 2026 16:41
@j4n j4n changed the title Add deadline support to Pinger Make Importable as Library Mar 10, 2026
@j4n
Copy link
Copy Markdown
Author

j4n commented Mar 10, 2026

Title got mixed up. This is for the chatmail prober, which is almost ready.

j4n added 2 commits March 23, 2026 14:09
- Add CMPingError exception for non-fatal error reporting
- Add set_cli_output() to let library callers suppress terminal output
- Convert sys.exit(1) to raise CMPingError in setup_accounts,
  wait_profiles_online, and wait_profiles_online_multi
- Add accounts_dir parameter to perform_ping() for concurrent probe
  isolation (each caller can use its own DB directory)
- Wrap perform_ping() in main() with try/except CMPingError
- Add logging module with log = getLogger("cmping")
- Convert all print() calls to log.debug/info/warning/error
- Add logging.basicConfig() in main() keyed to verbose level
- Change print_progress() to write to stderr with _cli_output guard
- Gate per-message RTT lines and statistics on _cli_output flag
- Replace Unicode spinner chars with ASCII for portability
@j4n j4n force-pushed the j4n/make-importable branch from 46ffa78 to 91e49c9 Compare March 23, 2026 13:21
import argparse
import contextlib
import ipaddress
import logging
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @hpk42 is not fun of this logging crate, I also don't like what it does in deltachat-rpc-client even though we use it and it is enabled at
https://github.com/chatmail/core/blob/aedc60f1ccb4f9898123d150662c058ac14ff61f/deltachat-rpc-client/tox.ini#L29-L30
It is surprising for users because output is in a different place from pytest runs that don't use it, it is not obvious where it is enabled (i looked into pyproject.toml before looking into tox.ini) etc.

@link2xt
Copy link
Copy Markdown
Contributor

link2xt commented Mar 23, 2026

Somewhat high-level comment: for https://github.com/j4n/chatmail-prober maybe it makes sense to "vendor" cmping into chatmail_prober/prober.py, remove all the prints and hardcode accounts directory and remove group pinging? There is not much code that is actually used and not having to monkeypatch print or using logging but just removing it may simplify the logic. If you only keep the logic needed for pinging and only depend on deltachat-rpc-server and deltachat-rpc-client prober could even be a long running process that does not need to worry about accounts.lock etc. if all accounts are constantly open and are maybe only stopped/started as needed to avoid keeping IMAP IDLE connection.


# Spinner characters for progress display
SPINNER_CHARS = ["", "", "", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
SPINNER_CHARS = ["|", "/", "-", "\\"]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace Unicode spinner chars with ASCII for portability

Reminds me of the days when I installed FreeBSD which back then did not support UTF-8. I think practically any system supports unicode now.

@j4n
Copy link
Copy Markdown
Author

j4n commented Mar 24, 2026

I agree, this is venturing far beyond the original scope and it makes more sense to interface with the RPC server directly. I have "vendored" the direct mode ping etc. into the prober, and indeed it become much easier / faster, so closing these PRs as obsolete.

@j4n j4n closed this Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants